package day1126;

import java.util.Timer;
import java.util.TimerTask;


class Marine{
    int x;
    void moveRight(){
        x++;
        System.out.println(x);
    }
}


public class Demo14 {

    public static void main(String[] args) {
        Marine  m=new Marine();
        //1.包含需要重复执行的代码
        TimerTask  t= new TimerTask() {
            public void run() {
                m.moveRight();
            }
        };
        //2.Timer的schedule()
        Timer tm=new Timer();
        tm.schedule( t ,2000,2000);
    }

}


